let map = {
    "address": "地址",
    "bornDate": "出生日期",
    "email": "电子邮箱",
    "gradeId": "年级",
    "identityCard": "身份证号",
    "loginPwd": "登录密码",
    "phone": "电话号码",
    "sex": "性别",
    "studentName": "学生姓名",
    "studentNo": "学号"
}

function getUserList() {
    fetch("http://localhost:8080/webProject_war_exploded/userList").then(r => r.json()).then(
        data => {
            const table = document.getElementById("table1");
            // 获取列表中元素的遍历 for of
            for (let datum of data) {
                // console.log(JSON.stringify(datum))
                const tr = table.appendChild(document.createElement("tr"));
                // 获取dict中键值对的遍历, for key in dict { 实际上value=dict{key} }
                for (let datumKey in datum) {
                    const td = tr.appendChild(document.createElement("td"));
                    if (datumKey in map) {
                        td.appendChild(document.createTextNode(map[datumKey] + ":" + datum[datumKey]))
                    } else {
                        td.appendChild(document.createTextNode(datumKey + ":" + datum[datumKey]))
                    }
                }
                const td = tr.appendChild(document.createElement("td"))
                td.appendChild(document.createTextNode("测试文本"))
            }
            // document.getElementById("p1").innerText = JSON.stringify(data)
        }
    )
}


// const personArray = [{"name": "小明", "age": 20}]
// // 取得dict中的value, 使用直接访问dict的key属性的方式
// console.log(personArray[0].age)


function delUserViaID() {
    document.getElementById("deleteState").innerText = "正在删除指定用户: " + document.getElementById('inputID').value + " ..."
    $.ajax({
        url: "http://localhost:8080/webProject_war_exploded/userDel?IdentityCard=" + document.getElementById('inputID').value,
        type: "GET",
    }).then(r => {
        document.getElementById("deleteState").innerText = r
    }).then(() => {
        setTimeout(function () {
            location.reload()
        }, 1500)
    })
}

// onLoad ?
// window.onload(getUserList());